package com.designschool.base.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.util.Log;

/***
 * 
 * @项目名:base
 * 
 * @类名:BitmapUtil.java
 * 
 * @创建人:shibaotong
 * 
 * @类描述:Bitmap的操作
 * 
 * @date:2014-1-7
 * 
 * @Version:1.0
 * 
 ***************************************** 
 */
public class BitmapUtil {
    private static File file = null;

    /***
     * 保存Bitmap到本地
     * 
     * @param bitName
     * @param mBitmap
     */
    public static void saveMyBitmap(String bitName, Bitmap mBitmap) {
    	if(!SdUtils.ExistSDCard())
    		return;
        file = new File("/mnt/sdcard/shi/" + bitName + ".png");
        if(!FileUtils.makeDirs("/mnt/sdcard/shi/"))
        {
            return ;
        }
        try {
            file.createNewFile();
        } catch (IOException e) {
            Log.e("errer==>", "在保存图片时出错：" + e.toString());
        }
        FileOutputStream fOut = null;
        try {
            fOut = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        try {
            fOut.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fOut.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    /***
     * 保存替换原有的图片
     * @param mBitmap
     */
    public static void saveMyBitmap(Bitmap mBitmap) {
    	if(!SdUtils.ExistSDCard())
    		return;
        file = new File("/mnt/sdcard/shi/shi.png");
        if(!FileUtils.makeDirs("/mnt/sdcard/shi/"))
        {
            return ;
        }
        try {
            file.createNewFile();
        } catch (IOException e) {
            Log.e("errer==>", "在保存图片时出错：" + e.toString());
        }
        FileOutputStream fOut = null;
        try {
            fOut = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        try {
            fOut.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fOut.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
